package com.song.osclient.view;

import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.song.osclient.App;
import com.song.osclient.R;


public class PrintToast extends Toast {

    public PrintToast(Context context) {
        super(context);
    }

    public static void print(String s) {
        getToast(App.getContext(), s, Toast.LENGTH_SHORT).show();
    }

    public static void print(Context context, CharSequence s) {
        getToast(context, s, 3000).show();
    }

    public static void print(Context context, int resId) {
        getToast(context, context.getResources().getString(resId), 3000).show();
    }

    public static void print(Context context, int resId, int duration) {
        getToast(context, context.getResources().getString(resId), duration).show();
    }

    private static Toast getToast(Context context, CharSequence s, int duration) {
        PrintToast toast = new PrintToast(context);
        toast.setDuration(duration);
        TextView view = new TextView(context);
        view.setHeight(App.dp2Px(60));
        view.setText(s);
        view.setTextColor(0xffffffff);
        view.setTextSize(15);
        view.setGravity(Gravity.CENTER);
        view.setBackgroundResource(R.drawable.bg_toast);
        toast.setView(view);
        toast.setGravity(Gravity.CENTER, 0, 0);
        return toast;
    }
}
